/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package naivebayes;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 *
 * @author Jaime
 */
public class NaiveBayes {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {
        // TODO code application logic here
        
        int firstPos = 14;
        int lastPos = 463;
        
        int firstNeg = 14;
        int lastNeg = 243;
        
        List<File> positives = new ArrayList<File>();
        List<File> negatives = new ArrayList<File>();
        int numberOfGroups = 10;
        
        System.out.println("This classifier is configured to classify:\nPositive files:");
        System.out.println("From "+firstPos+".txt to "+lastPos+".txt\nNegative files:");
        System.out.println("From "+firstNeg+".txt to "+lastNeg+".txt\n");
        
        System.out.println("Please, enter the folder to the input files."
                + "This folder must contain other two folders named: positive and negative,"
                + "each containing, respectively, the positive and the negative input files\n.");
        
        
        String folder = (new Scanner(System.in)).nextLine();
        //String folder = "/home/jaime/Desktop/tarefa NB/";
        //String folder = "C:\\Users\\Jaime\\Documents\\Mestrado\\"
         //       + "Aprendizagem de Máquina\\Trabalho1\\tarefa NB\\";
        String folderPos = folder+File.separator+"positivo"+File.separator;
        String folderNeg = folder+File.separator+"negativo"+File.separator;
        
        String resultsFile = folder+File.separator+"res.out";
        
        if(!(new File(folder)).isDirectory())
        {
            System.err.println("The entered folder is not valid.\n");
            System.exit(1);
        }
        
        if(!(new File(folderPos)).isDirectory())
        {
            System.err.println("The positive folder is not valid.\n");
            System.exit(1);
        }
        
        if(!(new File(folderNeg)).isDirectory())
        {
            System.err.println("The negative folder is not valid.\n");
            System.exit(1);
        }
        
        System.out.println("Printing report to:"+resultsFile);
        
        if((new File(resultsFile)).exists())
        {
            System.out.println("Warning: replacing old report file: "+resultsFile);
        }
        
        for(int i = firstPos; i <= lastPos; i++)
        {
            positives.add(new File(folderPos+i+".txt"));
        }
        
        for(int i = firstNeg; i <= lastNeg; i++)
        {
            negatives.add(new File(folderNeg+i+".txt"));
        }
        
        ModelsGenerator mg = new ModelsGenerator(numberOfGroups, positives, negatives);

        mg.trainAndTestAll();
        
        mg.storeResults(resultsFile);
        
        System.out.println("DONE");
        
    }
}
